﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MyRssReader
{
    /// <summary>
    /// Логика взаимодействия для Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        private Brush m_objParagraphMouseEnterbrush = Brushes.White;
        private LinearGradientBrush m_objParagraphMouseLeavebrush = new LinearGradientBrush()
                                                                    {
                                                                         GradientStops   = new GradientStopCollection()
                                                                                           {
                                                                                               new GradientStop(Colors.Yellow, 0.0),                
                                                                                               new GradientStop(Colors.Orange, 0.5),                
                                                                                               new GradientStop(Colors.Red, 1.0)                
                                                                                           }
                                                                    };

        public Window1()
        {
            InitializeComponent();
        }

        private void FlowDocument_MouseDown( object sender, MouseButtonEventArgs e )
        {
            //e.Source
            //MessageBox.Show( "das" );
        }

        private void Hyperlink_Click( object sender, RoutedEventArgs e )
        {
            //Binding b = BindingOperations.GetBinding( rssDescription, RssDescription.TextPropterty );
            Binding binding = BindingOperations.GetBinding(Flow1, FlowItemsControl.ItemsSourceProperty);

            MyRssReader.RssProvider source = ( RssProvider ) binding.Source;
            MyRssReader.Channel channel = ( Channel ) source.Data;

            System.Windows.Documents.Hyperlink hl = sender as System.Windows.Documents.Hyperlink ;
            if(hl == null)
            {
                Paragraph paragraph = sender as Paragraph;
                hl = paragraph.Inlines.FirstInline as Hyperlink;
            }

            string url = hl.NavigateUri.AbsoluteUri;
            List<MyRssReader.Item> items = channel.Items.ToList();
            Item selectItem = ( Item ) items.Where( n => ( n.Link == url ) ).First();
            rssDescription.Text = selectItem.Description;
       }

        private void Paragraph_MouseEnter(object sender, MouseEventArgs e)
        {

            ((Paragraph)sender).Background = m_objParagraphMouseLeavebrush;
        }

        private void Paragraph_MouseLeave(object sender, MouseEventArgs e)
        {
            ((Paragraph)sender).Background = m_objParagraphMouseEnterbrush;
        }

    }
}
